package com.chukun.disruptor.netty.server;

import com.chukun.disruptor.netty.bean.TranslatorData;
import com.chukun.disruptor.netty.disruptor.consumer.MessageConsumer;
import com.chukun.disruptor.netty.disruptor.entity.TranslatorDataWrapper;
import io.netty.channel.ChannelHandlerContext;

/**
 * 服务端,业务逻辑处理
 */
public class NettyServerConsumer  extends MessageConsumer {

    public NettyServerConsumer(String consumerID){
        super(consumerID);
    }

    @Override
    public void onEvent(TranslatorDataWrapper event) throws Exception {
        //1.业务逻辑处理
        TranslatorData request = event.getData();
        ChannelHandlerContext ctx = event.getCtx();
        System.err.println("Sever端: id= " + request.getId()
                + ", name= " + request.getName()
                + ", message= " + request.getMessage());

        //2.回送响应信息:
        TranslatorData response = new TranslatorData();
        response.setId("resp: " + request.getId());
        response.setName("resp: " + request.getName());
        response.setMessage("resp: " + request.getMessage());
        //写出response响应信息:
        ctx.writeAndFlush(response);
    }
}
